﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Xml;
using SMSSnew.smss_web_reference;

namespace SMSSnew.DATA.CLASSES
{
    public class teacherCLZ:userClZ
    {

        static smss_web_service_app srv = new smss_web_service_app();
        static readXML XMLreader = new readXML();

        public string teacher_id;


        public teacherCLZ()
        {
        }

        public teacherCLZ(string user_name, string password, string user_type, string e_mail, string phone_no, string full_name, string sec_question, string sec_answer, string teacher_id)
        {
            this.user_name = user_name;
            this.password = password;
            this.user_type = user_type;
            this.e_mail = e_mail;
            this.phone_no = phone_no;
            this.full_name = full_name;
            this.sec_question = sec_question;
            this.sec_answer = sec_answer;
            this.teacher_id = teacher_id;
        }



      
        public void setTeacherID(string teacher_id)
        {
            this.teacher_id = teacher_id;
        }

        public DataTable loadAllTeachers()
        {
            DataTable dt;
            string query = "";
            try
            {

                query = XMLreader.readXMLtxt("allTeachers", "~/DATA/XML/teacherXML.xml");
                dt = srv.Search(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        //.............method to take total number of allocated slots for a particular teacher.............

        public int takeTotalSlots(string teacher_id)
        {
            string query = "";
            int totalSlots = 0, t;
            DataTable dt;

            try
            {

                query = XMLreader.readXMLtxt("takeTotalNoOfSlots", "~/DATA/XML/teacherXML.xml");
                query = query.Replace("@teacherID", teacher_id);
                dt = srv.Search(query);


                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    t = int.Parse(dt.Rows[i][1].ToString());
                    totalSlots = totalSlots + t;

                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return totalSlots;
        }


        public void allocateTeachersForSubjects(subjectSubTypesCLZ subObj, classCLZ clasObj)
        {
            string query = "";
            string message = "";
            
            try
            {
                srv = new smss_web_service_app();
                query = XMLreader.readXMLtxt("allocateTeachersForSubjects", "~/DATA/XML/teacherXML.xml");


                query = query.Replace("@subjectTypeID", subObj.subject_sub_type_id);
                query = query.Replace("@teacher", this.teacher_id);
                query = query.Replace("@class", clasObj.class_id);
                                
                srv.Modify(query);
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
           
        }

    }
}
